package com.beyond.common.dp.theme

import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import com.beyond.common.ext.dataStore
import com.beyond.common.ext.put
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

object SystemPrimaryColorPreference {
    private const val SYSTEM_PRIMARY_COLOR = "SYSTEM_PRIMARY_COLOR"
    const val default = true
    private val key = booleanPreferencesKey(SYSTEM_PRIMARY_COLOR)

    fun put(context: Context, scope: CoroutineScope, value: Boolean) {
        scope.launch {
            context.dataStore.put(key, value)
        }
    }

    fun fromPreferences(preferences: Preferences) = preferences[key] ?: true
}
